﻿@{
    Layout = null;
}
@using CNKI.TPI.Web.Admin.Model;
@using CNKI.TPI.Web.Base;
<script>
    function addMenu() {
        $("#hiddenSysID").val(0);
        showMenu();
    }
    function editMenu(sysid, name, url, sort, type) {
        
        $("#hiddenSysID").val(sysid);
        $("#menuname").val(name);
        $("#menulink").val(url);
        $("#menusort").val(sort);
        if (type == 0) {
            $("input[name=typemenu]").eq(1).attr('checked', 'true');
        }
        else {
            $("input[name=typemenu]").eq(0).attr('checked', 'true');
        }
        showMenu();
    }
    function delMenu(sysid) {
        var urlstr = "@Html.Raw(Url.Action("DelMenu", "Admin_Home"))";
        var dataobj = { "sysid": sysid };
        confirmDialog('确定要删除吗?', function () {
            $.ajax({
                type: "GET",
                url: timestamp(urlstr),
                data: dataobj,
                success: function (msg) {
                    if (msg == "True") {
                        var urlstr = "@Html.Raw(Url.Action("MenuIndex", "Admin_Home"))";
                        ajaxLoad("initload", timestamp(urlstr)); //刷新列表页
                    }
                    else {
                        messageAlert("删除失败！");
                    }
                },
                error: function (e)
                { }
            })
        })
    }
    function saveMenu() {
        
        var mname = $("#menuname").val();
        if (mname == "") {
            messageAlert("菜单名称不能为空！");
            return;
        }
        var mlink = $("#menulink").val();
        //if (mlink == "") {
        //    messageAlert("菜单链接不能为空！");
        //    return;
        //}
        var msort = 0;
        if ($("#menusort").val() != "") {
            msort = $("#menusort").val();
        }
        var m = $("#hiddenSysID").val();
        var mtype = $("input[name=typemenu]:checked").val();
        var insertdata = { "NAME": mname, "URL": mlink, "Sort": msort, "Type": mtype, "MenuType": "检索模板", "SYSID": m };
        var saveurl = "@Html.Raw(Url.Action("SaveMenu", "Admin_Home"))";
        var savedata = { "obj": insertdata };
        $.ajax({
            type: "POST",
            url: saveurl,
            data: JSON.stringify(savedata),
            contentType: "application/json",
            success: function (m) {
                if (m == "True") {
                    closeMenu();
                    ajaxLoad("initload", '@Html.Raw(Url.Action("MenuIndex", "Admin_Home"))');
                }
                else {
                    messageAlert("操作失败！");
                }
            },
            error: function (e)
            { }
        })

    }
    function closeMenu() {
        $(".talkDivBg").hide();
        $(".addMenu").hide();
    }
    function showMenu() {
        $(".talkDivBg").show();
        $(".addMenu").show();
    }

    function closeSort() {
        $(".talkDivBg").hide();
        $(".sortMenu").hide();
    }
    function showSort() {
        $(".talkDivBg").show();
        $(".sortMenu").show();
    }
    function sortMenu() {


        if ($("#MenuCount").val() > 0) {
            //获取对应的数据
            $.ajax({
                type: "GET",
                url: timestamp("@Html.Raw(Url.Action("GetMenuList", "Admin_Home"))"),
                beforeSend: function () { $("#loading").show(); },
                success: function (msg) {
                    var obj = eval(msg);
                    $(".ulfield").empty();
                    if (obj != null && obj.length > 0) {
                        for (var i = 0; i < obj.length; i++) {
                            var listr = " <li class=\"f-ct\" style=\"margin-left: 2em;\">  <label class=\"f-label block right\">" +
                           " <input type=\"checkbox\" class=\"f-checkboxR\"  value='" + obj[i].SYSID + "' />" + obj[i].NAME + "</label></li>";
                            $(".ulfield").append(listr);
                        }
                    }
                    $("#loading").hide();
                    showSort();
                },
                error: function (e)
                { $("#loading").hide(); }

            })


        }
        else {
            messageAlert("暂无数据，不支持排序！");
        }
     
    }
    function saveSort() {
        var jsondata = [];
        $('.wrapR-c-box-b-right ul input').each(function (index) {
            var dataobj = {
                "SYSID": $(this).val(),
                "Sort": index
            }
            jsondata.push(dataobj);

        })
        var dataold = { "list": jsondata };
        $.ajax({
            type: "POST",
            url: "@Html.Raw(Url.Action("UpdateMenuSort", "Admin_Home"))",
               contentType: "application/json",
               data: JSON.stringify(dataold),
               success: function (msg) {
                   if (msg == "True") {
                       closeSort();
                       ajaxLoad("initload", '@Html.Raw(Url.Action("MenuIndex", "Admin_Home"))');

                }
                else {
                    messageAlert("操作失败！");
                }
            },
               error: function (e)
               { }
           })

    }
</script>
<div class="wrapR-c" style='padding-top: 20px; padding-bottom: 20px'>
    <div class='mb20 clearfix'>
        <a onclick="addMenu()" class="btn btn-m btn-submit btn-defa-f">添加</a>
        <a onclick="sortMenu()" class="btn btn-m btn-submit btn-defa-f">排序</a>
    </div>
    <input type="hidden" value="@ViewBag.MenuCount" id="MenuCount" />
     
    <table width="100%" cellspacing="0" cellpadding="0" border="0" class="table table-grey">
        <thead class='th-wr'>
            <tr class="thead">
                <th class="tdnum tdnum1">序号</th>
                <th>菜单名称</th>
                <th>菜单链接</th>
                <th>菜单类型</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @{if (ViewBag.MenuList != null)
              {
                  int sortno = 1;
                  string type = "非系统菜单";
                  foreach (SYS_CMS_NEWS_MENUCONFIG item in ViewBag.MenuList)
                  {
                      string str = "even";
                      if (sortno % 2 == 0)
                      {
                          str = "odd";
                      }
                      
                <tr class='@str'>
                    <td>@sortno</td>
                    <td class="tc">@item.NAME</td>
                    <td class="tc" style="text-align: left">@item.URL</td>
                    <td class="tc">
                        @if (item.Type == 1)
                        {
                            type = "系统菜单";
                        }
                        else
                        {
                            type = "非系统菜单";
                        }
                        @type
                    </td>
                    <td class="tc">
                        <a href="javascript:void(0);"   onclick="javascript:editMenu('@item.SYSID','@item.NAME','@item.URL','@item.Sort','@item.Type')">编辑</a>
                        <a  href="javascript:void(0);" onclick="delMenu('@item.SYSID')">删除</a>
                    </td>
                </tr>
                        sortno = sortno + 1;
                  }
              }
            }
        </tbody>
    </table>

</div>
<input type="hidden" id="hiddenSysID" />
<!--透明背景-->
<div class="talkDivBg" style="display: none; z-index: 999">
    <!--talkDiv弹出层(不带图片，宽550)-->
    <div class="talkDiv talkDivTr talkW-550 form-h addMenu" style='margin-top: -278px; display: none'>
        <div class="talkDiv-title">
            <span>首页菜单配置</span>
            <a class="icon icon-close" title="关闭" href="javascript:void(0);" onclick="closeMenu()"><i class="iconfont icon-error3"></i></a>
        </div>
        <div class="talkDiv-body talkDiv-body1">

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">菜单名称：</label>
                </div>
                <div class="f-ct">
                    <input type="text" value="" class="f-text span3" id="menuname" maxlength="32">
                    <span class="f-label-re">*</span>
                </div>
            </div>

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">显示顺序：</label>
                </div>
                <div class="f-ct">
                    <input type="text" value="" class="f-text span3" id="menusort" maxlength="5" onkeyup="value=value.replace(/[^\d.]/g,'')">
                </div>
            </div>

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">菜单链接：</label>
                </div>
                <div class="f-ct">
                    <input type="text" value="" class="f-text span3" id="menulink" maxlength="255">
                    @*<span class="f-label-re">*</span>*@
                </div>
            </div>

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">菜单类型：</label>
                </div>
                <div class="f-ct">
                    <label class="f-label">
                        <input type="radio" name="typemenu" value="1" checked="checked">系统菜单
                    </label>
                    <label class="f-label">
                        <input type="radio" name="typemenu" value="0">非系统菜单
                    </label>
                </div>
            </div>



            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label"></label>
                </div>
                <div class="f-ct" style="margin-left: 150px">
                    <a href="javascript:void(0);" class="btn btn-m btn-prim-f btn-submit" onclick="saveMenu()">保存</a> &#12288;
                    <a href="javascript:void(0);" class="btn btn-m btn-submit btn-defa-f" onclick="closeMenu()">取消</a>
                </div>
            </div>
        </div>
    </div>
    <div class="talkDiv talkDivTr talkW-550 form-h sortMenu" style='margin-top: -278px; display: none'>
        <div class="talkDiv-title">
            <span>首页菜单排序</span>
            <a class="icon icon-close" title="关闭" href="javascript:void(0);" onclick="closeSort()"><i class="iconfont icon-error3"></i></a>
        </div>
        <div class="talkDiv-body talkDiv-body1">
            <div class="f-gp" style="padding-left: 70px">
                <div class='wrapR-c-box wrapR-c-r wrapR-c-r-l' style="overflow-y: visible; height: 430px">
                    <div class="wrapR-c-box-t">菜单列表</div>
                    <div class="wrapR-c-box-b-right" style="overflow-y: scroll; height: 380px">
                        <ul class="ulfield">
                            @*  @if (ViewBag.MenuList != null)
                                {
                                    foreach (SYS_CMS_NEWS_MENUCONFIG item in ViewBag.MenuList)
                                    {

                                    <li class="f-ct" style="margin-left: 2em;">
                                        <label class="f-label block right">
                                            <input type="checkbox" class="f-checkboxR" value='@item.SYSID' />@item.NAME</label>

                                    </li>
                                    }
                                }*@
                        </ul>
                    </div>
                </div>

                <div class="wrapR-c-r-r form-h posa" style="top: 80px; left: 400px;">
                    <div>
                        <a title="移至最顶部" onclick=" movefirst(this)" class="iconfont-s iconfont-upest-s"></a>
                        <br />
                        <a title="上移" onclick="moveablove(this)" class="iconfont-s iconfont-up-s"></a>
                        <br />
                        <a title="下移" onclick="movedown(this)" class="iconfont-s iconfont-down-s"></a>
                        <br />
                        <a title="移至最底部" onclick="movelast(this)" class="iconfont-s iconfont-downest-s"></a>
                    </div>


                </div>
            </div>
            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label"></label>
                </div>
                <div class="f-ct" style="margin-left: 150px">
                    <a href="javascript:void(0);" class="btn btn-m btn-prim-f btn-submit" onclick="saveSort()">保存</a> &#12288;
                </div>
            </div>
        </div>
    </div>
</div>
